import logging
import redis
from flask import Flask
from flask_sqlalchemy import SQLAlchemy
from flask_wtf.csrf import CSRFProtect
from flask_session import Session
from config import config


db = SQLAlchemy()
redis_store = None

# 工厂函数
def create_app(config_name):
    pass

    app = Flask(__name__)

    # 配置信息
    app.config.from_object(config[config_name])

    # 配置数据库
    db.init_app(app)
    # 配置redis
    global redis_store
    redis_store = redis.StrictRedis(host=config[config_name].REDIS_HOST, port=config[config_name].REDIS_PORT)

    # CSRFProtect
    CSRFProtect(app)

    # 配置session
    Session(app)

    # 注册蓝图
    from info.modules.index import index_blu
    app.register_blueprint(index_blu)
    return app
#
# def setup_log(config_name):
#     """配置信息"""
#
#     # 设置日志的记录等级
#     logging.basicConfig(level=config[config_name].LOG_LEVEL)
